package com.eeepay.eeepay_v2.util;


import com.eeepay.eeepay_v2.model.WithdrawCashInfo;

import java.math.BigDecimal;

/**
 * 计算手续费的工具栏
 * Created by zw on 2016/11/14 0014.
 */
public class RateUtils {

    public static BigDecimal txRate(WithdrawCashInfo rateInfo, BigDecimal money){
        BigDecimal profitExp=null;
        try { //费率类型：1-每笔固定金额，2-扣率，3-扣率带保底封顶，4-扣率+固定金额,5-单笔阶梯 扣率
            switch(rateInfo.getRateType()){
                case "1":
                    profitExp = rateInfo.getSingleNumAmount();//每笔固定值
                    break;
                case "2":
                    profitExp = money.multiply(rateInfo.getRate()).divide(new BigDecimal(100));//单笔金额*扣率
                    break;
                case "3":
                    if(money.multiply(rateInfo.getRate()).divide(new BigDecimal(100)).compareTo(rateInfo.getCapping())==1){ //单笔金额*扣率 大于封顶 取封顶
                        profitExp=rateInfo.getCapping();//封顶金额
                    }else if(money.multiply(rateInfo.getRate()).divide(new BigDecimal(100)).compareTo(rateInfo.getSafeLine())==-1){//单笔金额*扣率 小于保底 取保底
                        profitExp=rateInfo.getSafeLine();//保底金额
                    }else{
                        profitExp=money.multiply(rateInfo.getRate()).divide(new BigDecimal(100));//单笔金额*扣率
                    }
                    break;
                case "4":
                    profitExp = money.multiply(rateInfo.getRate()).divide(new BigDecimal(100)).add(rateInfo.getSingleNumAmount());//单笔金额*扣率+每笔固定金额
                    break;
                case "5":
                    if(money.compareTo(rateInfo.getLadder1Max())==-1){ //单笔金额小于阶梯1
                        profitExp=money.multiply(rateInfo.getLadder1Rate());//单笔金额*阶梯1扣率
                    }
                    if(money.compareTo(rateInfo.getLadder1Max())!=-1 && money.compareTo(rateInfo.getLadder2Max())==-1){//单笔金额大于等于阶梯1 小于阶梯2
                        profitExp=money.multiply(rateInfo.getLadder2Rate());//单笔金额*阶梯2扣率
                    }
                    if(money.compareTo(rateInfo.getLadder2Max())!=-1 && money.compareTo(rateInfo.getLadder3Max())==-1){//单笔金额大于等于阶梯2 小于阶梯3
                        profitExp=money.multiply(rateInfo.getLadder3Rate());//单笔金额*阶梯3扣率
                    }
                    if(money.compareTo(rateInfo.getLadder3Max())!=-1 && money.compareTo(rateInfo.getLadder4Max())==-1){//单笔金额大于等于阶梯3 小于阶梯4
                        profitExp=money.multiply(rateInfo.getLadder4Rate());//单笔金额*阶梯4扣率
                    }
                    if(money.compareTo(rateInfo.getLadder4Max())!=-1){//单笔金额大于等于阶梯4
                            profitExp=money.multiply(rateInfo.getLadder4Rate());//单笔金额*阶梯4扣率
                    }
                default :
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profitExp;
    }

    public static BigDecimal getMinMoney(BigDecimal... moneys){
        BigDecimal min = moneys[0];
        for (int i = 0; i < moneys.length - 1; i++){
            if(min.compareTo(moneys[i + 1]) == 1){
                min = moneys[i + 1];
            }
        }
        return min;
    }

}
